class ServiceLinksController < ApplicationController
  before_filter :authorize
  
  # POST /service_links
  # POST /service_links.xml
  def create
    params[:service_link][:source_id] = current_user.id
    @service_link = ServiceLink.new(params[:service_link])
    
    respond_to do |format|
      if @service_link.save
        format.html { redirect_to(:back) }
        format.xml  { render :xml => @service_link, :status => :created, :location => @service_link }
      else
        format.html { redirect_to(:back) }
        format.xml  { render :xml => @service_link.errors, :status => :unprocessable_entity }
      end
    end
  end
  
  # DELETE /service_links/1
  # DELETE /service_links/1.xml
  def destroy
    @service_link = ServiceLink.find(params[:id])
    @service_link.destroy
    
    respond_to do |format|
      format.html { redirect_to(:back) }
      format.xml  { head :ok }
    end
  end
  
  protected
  
  def authorize 
    user = User.find_by_id(session[:user_id])
    unless user # NOT LOGGED IN
      session[:original_uri] = request.request_uri
      flash[:notice] = "Please log in" 
      redirect_to :controller => "home", :action => "login"
    end 
  end
  
end
